import os  
  
# 设置文件夹路径  
folder_path = r'process_way\pointnet2\data\point_cloud_models'  # 替换为你的文件夹路径  
output_file = r'process_way\pointnet2\data\point_cloud_models\filelist.txt'  # 输出文件的名称  
  
# 定义一个函数来递归地获取所有文件的相对路径  
def get_all_file_paths(root_dir):  
    file_paths = []  
    for dirpath, dirnames, filenames in os.walk(root_dir):  
        for filename in filenames:  
            # 获取文件的相对路径  
            file_path = os.path.relpath(os.path.join(dirpath, filename), root_dir)  
            file_paths.append(file_path)  
    return file_paths  
  
# 调用函数获取所有文件的相对路径  
all_file_paths = get_all_file_paths(folder_path)  
  
# 将路径写入txt文件  
with open(output_file, 'w') as f:  
    for path in all_file_paths:  
        f.write(path + '\n')  # 每个路径占一行  
  
print(f"所有文件的相对路径已保存到 {output_file}")